//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: () => import("./addSite.vue"),
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  data () {
    return {
      // 生成场地列表
      generateList: []
    }
  },
  buttons: {
    view: [], box: [], detail: [{
      name: "生成场地",
      icon: "ios-football",
      onClick () {
        this.generate();
      }
    }]
  },//扩展的按钮
  methods: {//事件扩展
    onInit () {
      //点击单元格编辑与结束编辑(默认是点击单元格编辑，鼠标离开结束编辑)
      this.detailOptions.clickEdit = true;
      // label宽度
      this.boxOptions.labelWidth = 120
      // 弹框宽度
      this.boxOptions.width = 1000
      // 开启单选
      //;
      // 内容超出后自动换行
      this.textInline = true;
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 从表添加按钮
      this.detail.columns.push({
        title: "操作",
        width: 165,
        render: (h, { row, column, index }) => {
          return h(
            "a",
            {
              props: {}, style: {},
              on: {
                click: () => {
                  // console.log("查看生成场地", row.mall_site);
                  let mall_site = row.mall_site
                  if (!mall_site) {
                    this.$Message.error("该场次没有场地！")
                  } else if (mall_site.length < 1) {
                    this.$Message.error("该场次没有场地！")
                  } else {
                    this.$refs.gridBody.open(mall_site)
                  }
                }
              }
            },
            "查看场地"
          )

        }
      })
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    // 生成场地按钮
    generate () {
      let rows = this.$refs.detail.getSelected()
      console.log("添加场地", rows);
      if (rows.length == 0) return this.$Message.error("请选择要生成场地的场次!");
      if (rows.length > 1) return this.$Message.error("不可批量生成场地!");
      console.log(rows[0].screen_number);
      console.log(rows[0].screen_time);
      console.log(rows[0].is_halftime);
      let date = rows[0]
      this.http
        .get(
          `api/Tube/GenerateSite?Number=${date.screen_number}&Time=${date.screen_time}&IsHalf=${date.is_halftime}`
        )
        .then((res) => {
          console.log("添加数据", res);
          if (res.status) {
            this.$Message.success(res.message);
            date.mall_site = res.data;
            console.log("添加数据", rows);
          } else {
            this.$Message.error(res.message);
          }
        });
    },
    addBefore (formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    // 保存前编辑 
    veriFromTable (formData) {
      console.log("保存前编辑", formData, this.generateList);
      let detailData = formData.detailData
      if (detailData.length > 0) {
        for (let index = 0; index < detailData.length; index++) {
          let element = detailData[index];
          let timeContainer = element.timeContainer
          let mall_site = detailData[index].mall_site
          if (!timeContainer) {
            this.$Message.error("请选择起止时间！")
            return false
          }

          if (timeContainer.length > 0 && timeContainer[0] != "") {
            element.screen_start_time = timeContainer[0]
            element.screen_end_time = timeContainer[1]
          } else {
            this.$Message.error("请选择起止时间！")
            return false
          }

          if (element.screen_name == "" || !element.screen_name) {
            this.$Message.error("请输入场次名称！")
            return false
          }

          if (element.screen_number == "" || !element.screen_number) {
            this.$Message.error("请输入场地数量！")
            return false
          }
          if (element.screen_time == "" || !element.screen_time) {
            this.$Message.error("请输入时段数量！")
            return false
          }
          if (!mall_site) {
            this.$Message.error('场次列表必须先生成场地! ')
            return false
          }
        }
        console.log("保存数据", formData);
        return true
      } else {
        this.$Message.error('至少添加一个场次列表! ')
        return false
      }
    },
    searchDetailAfter (data) {//查询从表后param查询参数,result回返查询的结果
      console.log("从表", data);
      data.forEach(item => {
        item.timeContainer = [item.screen_start_time, item.screen_end_time]
      })
      return true;
    },
  }
};
export default extension;